const getHomeworkById = require('../../../../../config').getHomeworkById
const deleteHomeworkByTeacher = require('../../../../../config').deleteHomeworkByTeacher
var util = require('../../../../../utils/util.js'); //addSubjectComplete

Page({
  data: {
    navItem: [{
      name : '543'
    } ],
    time: '',
		isscroll:true,
		inpTextarea:'还有需要特别说明的吗？搜索',
    inpTextafter:'还有需要特别说明的吗？的',
    staffinfo:null,
    current: 0
  },
  onLoad: function (option) {
    console.log( JSON.parse(option.staffinfo))
    let that = this
    let time = util.formatTime(new Date());
    let windowHeight = wx.getSystemInfoSync().windowHeight // 屏幕的高度
    let windowWidth = wx.getSystemInfoSync().windowWidth // 屏幕的宽度
    this.setData({
      scroll_height: windowHeight * 2,
      time: time,
      staffinfo: JSON.parse(option.staffinfo)
    })
    let parms = {
      homeworkId: JSON.parse(option.staffinfo).id
    }
    this.apiGetHomeWork(parms)
  },
  // api 查、查询老师添加的作业 2.删、删除该科目
  apiGetHomeWork(parms){
    wx.request({
      url: getHomeworkById,
      data: parms,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        console.log(res.data.data)
        this.setData({
          navItem: res.data.data
        })
      },
      fail: (res) => {
        console.log(res)
      }
    })
  },
  apiDelectSubject(parms){
    let that = this
    console.log(that.data.staffinfo)
    wx.request({
      url: deleteHomeworkByTeacher,
      data: parms,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        console.log(res)
        if(res.data.status == 200){
          wx.showToast({
            title: '删除科目成功',
            icon: 'success',
            duration: 2000
          })
          console.log()
          let data = {
            homeworkId: that.data.staffinfo.id
          }
          that.apiGetHomeWork(data)
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      },
      fail: (res) => {
        console.log(res)
      }
    })    
  },
  //api END
  previewImage: function (e) {
    wx.previewImage({
      current: e.currentTarget.id, // 当前显示图片的http链接
      urls: this.data.files // 需要预览的图片http链接列表
    })
  },
  // 切换泪目
  tabNav:function(e){
    let id = e.currentTarget.dataset.id
		this.setData({
			current: id
		})
  },
  // 删除科目
  delectSubject(e){
    console.log(e.currentTarget.dataset.id)
    let parms = {
      id: e.currentTarget.dataset.id
    }
    this.apiDelectSubject(parms)
  },
  // 滑动切换泪目
  bindchange(e){
    console.log(e)
    this.setData({
      current: e.detail.current
    })
  }
})